package com.itheima.d3_collection_traverse;

import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.function.Consumer;

/**
 * 目标：完成电影信息的展示。
 * new Movie("《肖生克的救赎》" , 9.7 ,  "罗宾斯")
 * new Movie("《霸王别姬》" , 9.6 ,  "张国荣、张丰毅")
 * new Movie("《阿甘正传》" , 9.5 ,  "汤姆.汉克斯")
 */
public class CollectionTest04 {
    public static void main(String[] args) {

        Collection<Movie> movieCollection = new ArrayList<>();
        movieCollection.add(new Movie("《肖生克的救赎》", 9.7, "罗宾斯"));
        movieCollection.add(new Movie("《霸王别姬》", 9.6, "张国荣、张丰毅"));
        movieCollection.add(new Movie("《阿甘正传》", 9.5, "汤姆.汉克斯"));
        System.out.println("--------");
        Iterator<Movie> integer = movieCollection.iterator();
        //快捷键  itit
        while (integer.hasNext()) {
            Movie next =  integer.next();
//不能应用的场景，在遍历的过程中，对集合中的元素进行删除或者添加
        }
        System.out.println("------------");

        //快捷键iter

        for (Movie movie : movieCollection) {
            System.out.println(movie.toString());
        }

        System.out.println("------------");
        movieCollection.forEach(new Consumer<Movie>() {
            @Override
            public void accept(Movie movie) {
                System.out.println(movie.toString());
            }
        });
        System.out.println("-----");
        movieCollection.forEach(movie -> System.out.println(movie.toString()));

        //list集合的专用迭代器



    }


}
